package cn.enilu.flash.service.shop;


import cn.enilu.flash.bean.entity.shop.Category;
import cn.enilu.flash.dao.shop.CategoryRepository;

import cn.enilu.flash.service.BaseService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.util.List;

@Service
public class CategoryService extends BaseService<Category,Long,CategoryRepository>  {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private CategoryRepository categoryRepository;

    @Autowired
    private EntityManager em;

//    public List<Category> findByFistId(Long id,Integer index,Integer size){
////        return categoryRepository.findByFistId(id);
////        String sql = "select * from t_shop_category where fist_id = ? limit ?,? ";
////        Query query = em.createNativeQuery(sql);
////        query.setParameter(1,id);
////        query.setParameter(2,index);
////        query.setParameter(3,size);
//        return (List<Category>)categoryRepository.queryfist(id,index,size);
//    }

    public Integer findByFistIdCount(Long id){
        return categoryRepository.countByFistId(id);
    }

    public List<Category> findByFistId(Long id){ return categoryRepository.findByFistId(id);}

    public List<Category> findByisHost(Integer isHost){
        return categoryRepository.findByIsHot(isHost);
    }
}

